package com.fjh.config;

import com.fjh.constant.QueueConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class OrderMqConfig {

    /**
     * 延迟队列
     * @return
     */
    @Bean
    public Queue msQueue(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-message-ttl", 120 * 1000);
        map.put("x-dead-letter-exchange", QueueConstant.ORDER_DEAD_EX);
        map.put("x-dead-letter-routing-key", QueueConstant.ORDER_DEAD_KEY);
        return new Queue(QueueConstant.ORDER_MS_QUEUE,true,false,false,map);
    }

    @Bean
    public Queue deadQueue() {
        return new Queue(QueueConstant.ORDER_DEAD_QUEUE);
    }

    @Bean
    public DirectExchange deadEx() {
        return new DirectExchange(QueueConstant.ORDER_DEAD_EX);
    }

    @Bean
    public Binding deadBind() {
        return BindingBuilder.bind(deadQueue()).to(deadEx()).with(QueueConstant.ORDER_DEAD_KEY);
    }
}
